package kku.cs.fgl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.SortedSet;

public class ActorSet extends ArrayList {
	
	public void put(Actor a){
	  int n=0,z=0;
	  Actor b;
	  for(int i=0;i<size();i++){
		b = (Actor)get(i);
		if(a.getZorder()<b.getZorder()){
		  n=i;
		  break;
		}
		n=i+1;
	  }
	  add(n,a);
	}
	
	public Actor[] toActorArray(){
		Actor[]all=new Actor[size()];
		toArray(all);
		return all;
	}
	public String toString(){
		String s="";
		Actor[] all = toActorArray();
		for(int i=0;i<all.length;i++){
			s = s+all[i].getName()+"("+all[i].getZorder()+") \n";
		}
		return s;
	}
	
	public void resort(){
		Collections.sort(this,new Comparator(){
			public int compare(Object arg0, Object arg1) {
				Actor a = (Actor)arg0;
				Actor b = (Actor)arg1;
				return a.getZorder()-b.getZorder();
			}			
		}); 
	}
}
